package edu.ymu.BMI.action;

import edu.ymu.BMI.vo.Form;
import edu.ymu.BMI.vo.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class PublicAction {


    @PostMapping("BMI")
    @ResponseBody
    public Result bMI(@RequestBody Form form) throws Exception{

        float sgf=Float.valueOf(form.getSg());
        float tzf=Float.valueOf(form.getTz());
        float result=0.0f;
        result=tzf/(sgf*sgf);


        String resultstr="";

        if(result<18.5){
            resultstr="过轻";
        }
        else if(result>=18.5&&result<=23.9){
            resultstr="正常";
        }
        else  if(result>=24&&result<=27){
            resultstr="过重";
        }
        else if(result>=28&&result<32){
            resultstr="肥胖";
        }
        else {
            resultstr="严重肥胖";
        }

        String suggest="";

        switch (resultstr){
            case "过轻":
                suggest="多吃点";
                break;
            case "正常":
                suggest="继续保持";
                break;
            case "过重":
                suggest="减肥啦";
                break;

            case "肥胖":
                suggest="吃点减肥药";
                break;
            default:
                suggest="绝食吧";
        }


        Result ro=new Result();
        ro.setResult(result);
        ro.setResultstr(resultstr);
        ro.setSuggest(suggest);



        return ro;



    }





}